<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="../../dist/css/layui.css">
    <script src="../../dist/layui.js"></script>
    <script src="../../dist/jquery-1_8_3.js"></script>
</head>
<body>

<form class="layui-form">

    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="firstPassword" required lay-verify="firstPassword" placeholder="请输入新密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">确认新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="secondPassword" required lay-verify="confirmPass" placeholder="请再次输入新密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 提交 -->
    <div style="margin-top: 30px">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal layui-block" lay-submit>提交</button>
        </div>
    </div>
</form>

</body>

<script>
    layui.use(['layer', 'form'], function(){
        var layer = layui.layer
            ,form = layui.form
            ,$ = layui.jquery;

        form.verify({
            firstPassword: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ],
            confirmPass : function(value) {
                if ($('input[name=firstPassword]').val() !== value)
                    return '两次密码输入不一致！';
            }
        });
        form.on('submit()',function(data){

            $.ajax({
                url:'/user/updatePassword',
                async: false,
                type:'post',
                data:data.field,
                // 是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true
                traditional: true,
                dataType:'JSON',
                success:function(result){
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    // 关闭父级弹出层
                    parent.layer.close(index);
                    parent.parent.layer.msg("修改成功！",{icon:1,time:1000});
                    // 刷新父页面
                    //parent.location.reload();
                }
            });
            return false;//组织表单默认提交并跳转
        });

    });
</script>
</html>
